<template>
	<div>
		<r-search ref="search" :searchData="searchData" :searchForm="searchForm" :searchHandle="searchHandle"
			:inline="true" />

		<r-table :isPagination="true" :isHandle="true" :tableData="tableData" :tableCols="tableCols"
			:tablePage="pagination" :loading="tableLoading" :tableHandles="tableHandles" :isSelection="false"
			@refresh="page()" />

		<r-form :formRules="formRules" :formHandle="formHandle" :formData="formData" :formCols="formCols" ref="elForm"
			labelWidth="100px" dialogWidth="500px" :isHandle="true" />
	</div>
</template>

<script>
export default {
	components: {},
	data() {
		return {
			searchData: {
				applyName: '',
				applyPhone: '',
				status: '',
				beginTime: '',
				endTime: ''
			},
			searchForm: [
				{ type: 'input', placeholder: '申请人名称', prop: 'applyName', width: 200 },
				{ type: 'input', placeholder: '手机号', prop: 'applyPhone', width: 200 },
				// {
				// 	type: 'daterange',
				// 	placeholder: '申请时间',
				// 	prop: 'date',
				// 	width: 300,
				// 	change: e => {
				// 		if (e) {
				// 			console.log(e);
				// 			this.searchData.beginTime = e[0]
				// 			this.searchData.endTime = e[1]
				// 		} else {
				// 			this.searchData.beginTime = ''
				// 			this.searchData.endTime = ''
				// 		}
				// 	}
				// },
				{
					type: "date", placeholder: "开始日期", prop: "beginTime", width: 170, change: (val) => { this.searchData.beginTime = val }
				},
				{
					type: "date", placeholder: "结束日期", prop: "endTime", width: 170, change: (val) => { this.searchData.endTime = val }
				},
				{
					type: 'select',
					placeholder: '审核结果',
					prop: 'status',
					width: 200,
					options: [{ label: '待审核', value: '1' }, { label: '已通过', value: '2' }, { label: '不通过', value: '3' }]
				}
			],
			searchHandle: [
				{ type: 'primary', label: '搜索', handle: e => this.getData() }
				// {type:'primary',label:'重置', handle: e => this.elFormSubmit(),}
			],
			tableLoading: false,
			tableData: [{}],
			tableCols: [
				{ label: 'ID', prop: 'id' },
				{ label: '订单编号', prop: 'orderNo' },
				{ label: '订单类型', prop: 'type' },
				// 1 待审核 2已通过 3不通过
				{
					label: '订单状态',
					prop: 'status',
					itemClass: e => (e.status == 2 ? 'success' : e.status == 3 ? 'danger' : ''),
					formatter: e => (e.status == 1 ? '待审核' : e.status == 2 ? '已通过' : e.status == 3 ? '不通过' : '--')
				},
				// { label: "是否已归还设备", prop: "consumptionMoney",  },
				{ label: '用户信息', prop: 'applyName' },
				{ label: '用户手机', prop: 'applyPhone' },
				// { label: "提现信息", prop: "isVip_des",  },
				{ label: '订单预支付押金', prop: 'money' },
				// { label: "剩余押金", prop: "isVip_des",  },
				{ label: '申请时间', prop: 'ctime' },
				// { label: "审核结果", prop: "isVip_des",  },
				{ label: '审核反馈', prop: 'rejectReason' },
				{
					label: '操作',
					type: 'button',
					width: 200,
					btnList: [
						{
							label: '通过',
							type: 'text',
							isShow: e => e.status == 1,
							handle: row => {
								this.$confirm('确定通过申请吗?', '提示', {
									confirmButtonText: '确定',
									cancelButtonText: '取消',
									type: 'warning'
								})
									.then(async () => {
										const res = await this.apis.depositReturn_check({
											id: row.id,
											status: 2
										})

										this.$message({
											message: '操作成功！',
											type: 'success'
										})
										this.getData()
									})
									.catch(() => { })
							}
						},
						{
							label: '不通过',
							type: 'text',
							isShow: e => e.status == 1,
							handle: row => {
								this.formData.id = row.id
								this.elFormVisible('驳回')
							}
						}
					]
				}
			],
			tableHandles: [
				// {
				//   label: "导出",
				//   type: "primary",
				//   handle: e => this.elFormVisible()
				// },
			],
			pagination: { limit: 10, offset: 1, total: 1 },

			checkBox: [],

			formData: {
				id: '',
				status: 3,
				rejectReason: ''
			},
			formCols: [{ type: 'input', label: '拒绝原因', width: 350, prop: 'rejectReason', rmblock: true, remark: '' }],
			formRules: {
				rejectReason: [{ required: true, message: '请输入', trigger: 'blur' }]
			},
			formHandle: [
				{
					label: '取消',
					handle: e => this.elFormVisible()
				},
				{
					label: '确定',
					type: 'success',
					handle: e => this.elFormSubmit()
				}
			]
		}
	},
	created() { },
	mounted() {
		this.getData()
	},
	methods: {
		async getData() {
			var res = await this.apis.depositReturn_list({
				applyPhone: this.searchData.applyPhone,
				applyName: this.searchData.applyName,
				status: this.searchData.status,
				beginTime: this.searchData.beginTime,
				endTime: this.searchData.endTime,
				pageNum: this.pagination.offset,
				pageSize: this.pagination.limit
			})
			var list = res.rows || []

			this.tableData = list
			this.pagination.total = res.total
		},
		async elFormSubmit(row) {
			this.$refs.elForm.$refs.ruleForm.validate(async valid => {
				if (valid) {
					const res = await this.apis.depositReturn_check(this.formData)

					this.$message({
						message: '操作成功！',
						type: 'success'
					})
					this.getData()
				}
			})
		},
		page() {
			this.getData()
		}
	}
}
</script>

<style scoped lang="scss">
</style>
